package net.moonbiter.ebs.exposer;

import net.moonbiter.ebs.BusinessProvider;
import net.moonbiter.ebs.BusinessService;
import net.moonbiter.ebs.Input;

@BusinessProvider("rubrica")
public class RubricaService {
	
	public static class Persona {
		private String nome;
		private String cognome;
		
		public String getNome() {
			return nome;
		}
		public void setNome(String nome) {
			this.nome = nome;
		}
		public String getCognome() {
			return cognome;
		}
		public void setCognome(String cognome) {
			this.cognome = cognome;
		}		
	}
	
	public static class Computer{
		private int mhz;

		public int getMhz() {
			return mhz;
		}

		public void setMhz(int mhz) {
			this.mhz = mhz;
		}
		
	}
	
	public static class Contatto {
		private Persona persona;
		private long[] numeri;
		private String[] emails;
		public Persona getPersona() {
			return persona;
		}
		public void setPersona(Persona persona) {
			this.persona = persona;
		}
		public long[] getNumeri() {
			return numeri;
		}
		public void setNumeri(long[] numeri) {
			this.numeri = numeri;
		}
		public String[] getEmails() {
			return emails;
		}
		public void setEmails(String[] emails) {
			this.emails = emails;
		}
	}
	
	@BusinessService
	public String valuta(@Input(name="c")Computer c){
		if (c.getMhz()>500){
			return "BUONO!";
		} else {
			return "FA SCHIFO!";
		}
	}

	@BusinessService("registerNumber")
	public void registerNumber(@Input(name="persona")Persona persona,
			@Input(name="numero")long numeroDiTelefono){
		System.out.println("Ok, mo mi segno tutto...");
		System.out.println("  "+persona.getNome());
		System.out.println("  "+persona.getCognome());
		System.out.println("  "+numeroDiTelefono);
	}
	
	@BusinessService("registerPeople")
	public void registerNumber(@Input(name="p")Persona[] persone){
		System.out.println("Persone indicate: "+persone.length);
		int i=0;
		for (Persona p : persone){
			System.out.println((i++)+") "+p.nome+", "+p.cognome);
		}
		
	}
	
	@BusinessService("registerContacts")
	public void registerContacts(@Input(name="c")Contatto[] contatti){
		System.out.println("Contatti indicate: "+contatti.length);
		int i=0;
		for (Contatto c : contatti){
			System.out.println((i++)+") "+c.getPersona().getNome()+", "
					+c.getPersona().getCognome());
			System.out.println("  e-mails: "+c.getEmails().length);
			for (String email:c.getEmails()){
				System.out.println("    "+email);
			}
			System.out.println("  numeri: "+c.getNumeri().length);
			for (long n : c.getNumeri()){
				System.out.println("    "+n);
			}
		}
		
	}
}
